package learn1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("赵六");
        list.add("王二");
        list.add("张强");
        list.add("张本智和");

        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        ArrayList<String> list2 = new ArrayList<String>();
        for (String s : list) {
            if (s.startsWith("张")) {
                list2.add(s);
            }
        }
        System.out.println(list2);

        ArrayList<String> list3 = new ArrayList<String>();
        for (String s: list2) {
            if (s.length()==4) {
                list3.add(s);
            }
        }
        System.out.println(list3);

        list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length()==4).forEach(s -> System.out.println(s));



    }
}
